classdef TestAnimatedMesh < handle
properties 
        mRefMesh
        mAM = 0;
        mNumberFrames = 0;
        mAdjList % adjacent faces
        mAdjVertList % adjacent vertices
    end % properties
    methods
         % Constructor 
        function obj = TestAnimatedMesh(fileName)                      
            % Create adjacency lists
            addpath(genpath('..'));
            addpath(genpath('../obj-tools'));
            [o.vertices, o.faces] = read_wobj([fileName '.obj']);
            obj.mAM.frames = toVector(o.vertices);
            obj.mAM.topology = o.faces;
            obj.mRefMesh = Mesh(obj.mAM.frames(1,:), o.faces);
            [obj.mNumberFrames] = size(obj.mAM.frames, 1);
            try
                adj = load([fileName 'Adj.mat']);
                obj.mAdjList = adj.adjList;
                obj.mAdjVertList = adj.adjVertList;
            catch err
                adjList = createAdjacencyList(obj.mRefMesh.mFaces, obj.mRefMesh.mNumberV, obj.mRefMesh.mNumberF);
                adjVertList = createVertexAdjacencyList(obj.mRefMesh.mFaces, obj.mRefMesh.mNumberV, obj.mRefMesh.mNumberF);
                obj.mAdjList = adjList;
                obj.mAdjVertList = adjVertList;
                save([fileName 'Adj.mat'], 'adjList', 'adjVertList');
            end
        end % Constructor
        function [mesh] = getMeshForFrame(obj, frameId)
            mesh = Mesh(obj.mAM.frames(frameId, :), obj.mAM.topology);
        end % function getMeshForFrame
    end
    
end % classdef

